/***************************************************************************
* COPYRIGHT NOTICE
* Copyright 2019 Horizon Robotics, Inc.
* All rights reserved.
***************************************************************************/
#ifndef UTILITY_SENSOR_INC_SC132GS_SETTING_H_
#define UTILITY_SENSOR_INC_SC132GS_SETTING_H_

#ifdef __cplusplus
extern "C" {
#endif


#ifndef trace
#define trace(fmt,args...) if(1) do{printf("[%s,%d]"fmt,__func__,__LINE__,##args);}while(0)
#endif
#define MCLK (24000000)



#define SC132GS_SHR0 (0x3050)
#define SC132GS_SHR1 (0x3054)
#define SC132GS_SHR2 (0x3058)
#define SC132GS_SHR3 (0x305C)

#define SC132GS_RHS1 (0x3060) // Readout timing setting of SEF1 Designated in line units.
#define SC132GS_RHS2 (0x3064) // Readout timing setting of SEF2 Designated in line units. 

#define GAIN_PCG0   (0x3090)
#define GAIN_PCG1   (0x3092)
#define GAIN_PCG2   (0x3094)
#define GAIN_PCG3   (0x3094)


#define SC132GS_VAMX (0x320c)
#define SC132GS_HAMX (0x320e)

#define PIX_HST (0x3040) 
#define PIX_VST (0x3044) 

#define PIX_HWIDTH (0x3042) //  PIX_HWIDTH
#define PIX_VWIDTH (0x3046) //  PIX_VWIDTH

#define SC132GS_PARAM_HOLD  	(0x3001)
#define SC132GS_LINE      	(0x3050)
#define SC132GS_GAIN         (0x3e08)
#define SC132GS_DGAIN		(0x3e06)

#define SC132GS_CSI_LANE_MODE (0x4001)  // 1:CSI-2 2lane, 3:CSI-2 4lane

// #define SC132GS_VTS	       	(0x0340)
// #define SC132GS_HTS	        (0x0342)
// #define SC132GS_X_SIZE   	(0x034C)
// #define SC132GS_Y_SIZE  		(0x034E)
// #define DEFAULT_FPS_REGVALUE	(3064)
// #define DEFAULT_FPS				(30)


#define SC132GS_REG_CTRL_MODE 0x3000
#define SC132GS_MODE_SW_STANDBY 0x1
#define SC132GS_MODE_STREAMING 0x0

#define SC132GS_REG_MASTER_MODE 0x3002
#define SC132GS_MASTER_MODE_START 0x0
#define SC132GS_MASTER_MODE_STOP 0x1

typedef enum SC132GS_FPS_TYPE
{
	SC132GS_30FPS = 30,
	SC132GS_60FPS = 60,
} SEN_FPS_TYPE_E;

static uint32_t sc132gs_stream_on_setting[] = {
        0x0100, 0x1,
};

static uint32_t sc132gs_stream_off_setting[] = {
        0x0100, 0x0,
};

static uint32_t sc132gs_4lane_init_1088x1280_slave_setting[] = {
	0x0103,0x01,
	0x0100,0x00,
	0x36e9,0x80,
	0x36f9,0x80,
	0x300a,0x62,
	0x3018,0x72,
	0x3019,0x00,
	0x301a,0xb4,
	0x301f,0xbe,
	0x3032,0x60,
	0x3038,0x44,
	
	0x3200,0x00,
	0x3201,0x02,
	0x3202,0x00,
	0x3203,0x02,
	0x3204,0x04,
	0x3205,0x55,
	0x3206,0x05,
	0x3207,0x15,
	0x3208,0x04,
	0x3209,0x40,
	0x320a,0x05,
	0x320b,0x00,
	0x3210,0x00,
	0x3211,0x0a,
	0x3212,0x00,
	0x3213,0x0a,
	
	0x320c,0x02,
	0x320d,0xee,
	0x320e,0x05,
	0x320f,0x78,
	// 0x3222,0x02,
	0x3223,0x44,
	0x3225,0x04,
	0x3226,0x06,
	0x3227,0x06,
	0x3228,0x05,
	0x3229,0x72,
	0x322b,0x0b,
	0x3231,0x28,
	0x3250,0xcc,
	0x3251,0x02,
	0x3252,0x05,
	0x3253,0x73,
	0x3254,0x05,
	0x3255,0x3b,
	0x3306,0x78,
	0x330a,0x00,
	0x330b,0xc8,
	0x330f,0x24,
	0x3314,0x80,
	0x3315,0x40,
	0x3317,0xf0,
	0x331f,0x12,
	0x3364,0x00,
	0x3385,0x41,
	0x3387,0x41,
	0x3389,0x09,
	0x33ab,0x00,
	0x33ac,0x00,
	0x33b1,0x03,
	0x33b2,0x12,
	0x33f8,0x02,
	0x33fa,0x01,
	0x3409,0x08,
	0x34f0,0xc0,
	0x34f1,0x20,
	0x34f2,0x03,
	0x3622,0xf5,
	0x3630,0x5c,
	0x3631,0x80,
	0x3632,0xc8,
	0x3633,0x32,
	0x3638,0x2a,
	0x3639,0x07,
	0x363b,0x48,
	0x363c,0x83,
	0x363d,0x10,
	0x36ea,0x36,
	0x36eb,0x04,
	0x36ec,0x13,
	0x36ed,0x24,
	0x36fa,0x2b,
	0x36fb,0x1b,
	0x36fc,0x11,
	0x36fd,0x34,
	0x3900,0x11,
	0x3901,0x05,
	0x3902,0xc5,
	0x3904,0x04,
	0x3908,0x91,
	0x391e,0x00,
	0x3e01,0x57,
	0x3e02,0x00,
	0x3e09,0x20,
	0x3e0e,0xd2,
	0x3e14,0xb0,
	0x3e1e,0x7c,
	0x3e26,0x20,
	0x4418,0x38,
	0x4503,0x10,
	0x4800,0x24,
	0x4837,0x35,
	0x5000,0x0e,
	0x540c,0x51,
	0x550f,0x38,
	0x5780,0x67,
	0x5784,0x10,
	0x5785,0x06,
	0x5787,0x02,
	0x5788,0x00,
	0x5789,0x00,
	0x578a,0x02,
	0x578b,0x00,
	0x578c,0x00,
	0x5790,0x00,
	0x5791,0x00,
	0x5792,0x00,
	0x5793,0x00,
	0x5794,0x00,
	0x5795,0x00,
	0x5799,0x04,
	0x36e9,0x54,
	0x36f9,0x50
	// 0x0100,0x01,

};

static uint32_t sc132gs_2lane_init_1088x1280_slave_setting[] = {
	0x0103,0x01,
	0x0100,0x00,
	0x36e9,0x80,
	0x36f9,0x80,
	0x300a,0x62,
	0x3018,0x32,
	0x3019,0x00,
	0x301a,0xb4,
	0x301f,0xbe,
	0x3032,0x60,
	0x3038,0x44,
	
	0x3200,0x00,
	0x3201,0x02,
	0x3202,0x00,
	0x3203,0x02,
	0x3204,0x04,
	0x3205,0x55,
	0x3206,0x05,
	0x3207,0x15,
	0x3208,0x04,
	0x3209,0x40,
	0x320a,0x05,
	0x320b,0x00,
	0x3210,0x00,
	0x3211,0x0a,
	0x3212,0x00,
	0x3213,0x0a,
	
	0x320c,0x02,
	0x320d,0xee,
	0x320e,0x05,
	0x320f,0x78,
	// 0x3222,0x02,
	0x3223,0x44,
	0x3225,0x04,
	0x3226,0x06,
	0x3227,0x06,
	0x3228,0x05,
	0x3229,0x72,
	0x322b,0x0b,
	0x3231,0x28,
	0x3250,0xcc,
	0x3251,0x02,
	0x3252,0x05,
	0x3253,0x73,
	0x3254,0x05,
	0x3255,0x3b,
	0x3306,0x78,
	0x330a,0x00,
	0x330b,0xc8,
	0x330f,0x24,
	0x3314,0x80,
	0x3315,0x40,
	0x3317,0xf0,
	0x331f,0x12,
	0x3364,0x00,
	0x3385,0x41,
	0x3387,0x41,
	0x3389,0x09,
	0x33ab,0x00,
	0x33ac,0x00,
	0x33b1,0x03,
	0x33b2,0x12,
	0x33f8,0x02,
	0x33fa,0x01,
	0x3409,0x08,
	0x34f0,0xc0,
	0x34f1,0x20,
	0x34f2,0x03,
	0x3622,0xf5,
	0x3630,0x5c,
	0x3631,0x80,
	0x3632,0xc8,
	0x3633,0x32,
	0x3638,0x2a,
	0x3639,0x07,
	0x363b,0x48,
	0x363c,0x83,
	0x363d,0x10,
	0x36ea,0x36,
	0x36eb,0x04,
	0x36ec,0x13,
	0x36ed,0x24,
	0x36fa,0x2b,
	0x36fb,0x1b,
	0x36fc,0x11,
	0x36fd,0x34,
	0x3900,0x11,
	0x3901,0x05,
	0x3902,0xc5,
	0x3904,0x04,
	0x3908,0x91,
	0x391e,0x00,
	0x3e01,0x57,
	0x3e02,0x00,
	0x3e09,0x20,
	0x3e0e,0xd2,
	0x3e14,0xb0,
	0x3e1e,0x7c,
	0x3e26,0x20,
	0x4418,0x38,
	0x4503,0x10,
	0x4800,0x24,
	0x4837,0x35,
	0x5000,0x0e,
	0x540c,0x51,
	0x550f,0x38,
	0x5780,0x67,
	0x5784,0x10,
	0x5785,0x06,
	0x5787,0x02,
	0x5788,0x00,
	0x5789,0x00,
	0x578a,0x02,
	0x578b,0x00,
	0x578c,0x00,
	0x5790,0x00,
	0x5791,0x00,
	0x5792,0x00,
	0x5793,0x00,
	0x5794,0x00,
	0x5795,0x00,
	0x5799,0x04,
	0x36e9,0x54,
	0x36f9,0x50
	// 0x0100,0x01,

};
static uint32_t sc132gs_again_lut[] = {
	0x0320,
	0x0321,
	0x0322,
	0x0323,
	0x0324,
	0x0325,
	0x0326,
	0x0327,
	0x0328,
	0x0329,
	0x032A,
	0x032B,
	0x032C,
	0x032D,
	0x032E,
	0x032F,
	0x0330,
	0x0331,
	0x0332,
	0x0333,
	0x0334,
	0x0335,
	0x0336,
	0x0337,
	0x0338,
	0x0339,
	0x2320,
	0x2321,
	0x2322,
	0x2323,
	0x2324,
	0x2325,
	0x2326,
	0x2327,
	0x2328,
	0x2329,
	0x232A,
	0x232B,
	0x232C,
	0x232D,
	0x232E,
	0x232F,
	0x2330,
	0x2331,
	0x2332,
	0x2333,
	0x2334,
	0x2335,
	0x2336,
	0x2337,
	0x2338,
	0x2339,
	0x233A,
	0x233B,
	0x233C,
	0x233D,
	0x233E,
	0x233F,
	0x2720,
	0x2721,
	0x2722,
	0x2723,
	0x2724,
	0x2725,
	0x2726,
	0x2727,
	0x2728,
	0x2729,
	0x272A,
	0x272B,
	0x272C,
	0x272D,
	0x272E,
	0x272F,
	0x2730,
	0x2731,
	0x2732,
	0x2733,
	0x2734,
	0x2735,
	0x2736,
	0x2737,
	0x2738,
	0x2739,
	0x273A,
	0x273B,
	0x273C,
	0x273D,
	0x273E,
	0x273F,
	0x2F20,
	0x2F21,
	0x2F22,
	0x2F23,
	0x2F24,
	0x2F25,
	0x2F26,
	0x2F27,
	0x2F28,
	0x2F29,
	0x2F2A,
	0x2F2B,
	0x2F2C,
	0x2F2D,
	0x2F2E,
	0x2F2F,
	0x2F30,
	0x2F31,
	0x2F32,
	0x2F33,
	0x2F34,
	0x2F35,
	0x2F36,
	0x2F37,
	0x2F38,
	0x2F39,
	0x2F3A,
	0x2F3B,
	0x2F3C,
	0x2F3D,
	0x2F3E,
	0x2F3F,
	0x3F20,
	0x3F21,
	0x3F22,
	0x3F23,
	0x3F24,
	0x3F25,
	0x3F26,
	0x3F27,
	0x3F28,
	0x3F29,
	0x3F2A,
	0x3F2B,
	0x3F2C,
	0x3F2D,
	0x3F2E,
	0x3F2F,
	0x3F30,
	0x3F31,
	0x3F32,
	0x3F33,
	0x3F34,
	0x3F35,
	0x3F36,
	0x3F37,
	0x3F38,
	0x3F39,
	0x3F3A,
	0x3F3B,
	0x3F3C,
	0x3F3D,
	0x3F3E,
	0x3F3F,
};

static uint32_t sc132gs_dgain_lut[] = {
	0x0080,
	0x0084,
	0x0088,
	0x008C,
	0x0090,
	0x0094,
	0x0098,
	0x009C,
	0x00A0,
	0x00A4,
	0x00A8,
	0x00AC,
	0x00B0,
	0x00B4,
	0x00B8,
	0x00BC,
	0x00C0,
	0x00C4,
	0x00C8,
	0x00CC,
	0x00D0,
	0x00D4,
	0x00D8,
	0x00DC,
	0x00E0,
	0x00E4,
	0x00E8,
	0x00EC,
	0x00F0,
	0x00F4,
	0x00F8,
	0x00FC,
	0x0180,
	0x0184,
	0x0188,
	0x018C,
	0x0190,
	0x0194,
	0x0198,
	0x019C,
	0x01A0,
	0x01A4,
	0x01A8,
	0x01AC,
	0x01B0,
	0x01B4,
	0x01B8,
	0x01BC,
	0x01C0,
	0x01C4,
	0x01C8,
	0x01CC,
	0x01D0,
	0x01D4,
	0x01D8,
	0x01DC,
	0x01E0,
	0x01E4,
	0x01E8,
	0x01EC,
	0x01F0,
	0x01F4,
	0x01F8,
	0x01FC,
	0x0380,
	0x0384,
	0x0388,
	0x038C,
	0x0390,
	0x0394,
	0x0398,
	0x039C,
	0x03A0,
	0x03A4,
	0x03A8,
	0x03AC,
	0x03B0,
	0x03B4,
	0x03B8,
	0x03BC,
	0x03C0,
	0x03C4,
	0x03C8,
	0x03CC,
	0x03D0,
	0x03D4,
	0x03D8,
	0x03DC,
	0x03E0,
	0x03E4,
	0x03E8,
	0x03EC,
	0x03F0,
	0x03F4,
	0x03F8,
	0x03FC,
	0x0780,
	0x0784,
	0x0788,
	0x078C,
	0x0790,
	0x0794,
	0x0798,
	0x079C,
	0x07A0,
	0x07A4,
	0x07A8,
	0x07AC,
	0x07B0,
	0x07B4,
	0x07B8,
	0x07BC,
	0x07C0,
	0x07C4,
	0x07C8,
	0x07CC,
	0x07D0,
	0x07D4,
	0x07D8,
	0x07DC,
	0x07E0,
	0x07E4,
	0x07E8,
	0x07EC,
	0x07F0,
	0x07F4,
	0x07F8,
	0x07FC,
	0x0F80,
	0x0F84,
	0x0F88,
	0x0F8C,
	0x0F90,
	0x0F94,
	0x0F98,
	0x0F9C,
	0x0FA0,
	0x0FA4,
	0x0FA8,
	0x0FAC,
	0x0FB0,
	0x0FB4,
	0x0FB8,
	0x0FBC,
	0x0FC0,
	0x0FC4,
	0x0FC8,
	0x0FCC,
	0x0FD0,
	0x0FD4,
	0x0FD8,
	0x0FDC,
	0x0FE0,
	0x0FE4,
	0x0FE8,
	0x0FEC,
	0x0FF0,
	0x0FF4,
	0x0FF8,
	0x0FFC,
};


#ifdef __cplusplus
}
#endif

#endif  // UTILITY_SENSOR_INC_SC132GS_SETTING_H_

